//
//  AddaBankCardViewController.m
//  BusinessApp
//
//  Created by CccDaxIN on 2016/10/7.
//  Copyright © 2016年 macox. All rights reserved.
//

#import "AddaBankCardViewController.h"

@interface AddaBankCardViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *OwnCardName;
@property (weak, nonatomic) IBOutlet UITextField *BrankNum;
@property (weak, nonatomic) IBOutlet UITextField *OwnCardNameProfession;
@property (weak, nonatomic) IBOutlet UITextField *AccountName;

@end

@implementation AddaBankCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"添加银行卡";
    _OwnCardName.delegate = self;
    _BrankNum.delegate = self;
    _OwnCardNameProfession.delegate = self;
    _AccountName.delegate = self;
    /*
     *返回
     */
    UIImage *bankCardBackImage = [UIImage imageNamed:@"左箭头"];
    bankCardBackImage = [bankCardBackImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:bankCardBackImage style:UIBarButtonItemStylePlain target:self action:@selector(bankCardBackAction)];

    // Do any additional setup after loading the view from its nib.
}
- (void)requestData{
    NSDictionary *param = @{@"ShouJiHao":GETPHONE,@"Duuid":GETUUID,@"Token":GETTOKEN,@"IDCardNum":_OwnCardNameProfession.text,@"BankAccountNumber":_BrankNum.text,@"BankName":_AccountName.text,@"BankAccountName":_OwnCardName.text};
    [GDJHttpTool post:DoSaveBankInfo params:param success:^(id responseObj) {
        NSLog(@"2222%@",responseObj);
        NSLog(@"2222121121%@",param);
        
        if (0 == [[responseObj valueForKey:@"Err"]integerValue] ) {
            [SVProgressHUD showSuccessWithStatus:@"修改成功" ];
            [self.navigationController popViewControllerAnimated:YES];
            
        }
        if (701 == [[responseObj valueForKey:@"Err"]integerValue] ) {
            [SVProgressHUD showErrorWithStatus:@"身份证长度不正确" ];
        }
        if (702 == [[responseObj valueForKey:@"Err"]integerValue] ) {
            [SVProgressHUD showErrorWithStatus:@"开户账号长度不正确" ];
        }
    } failure:^(NSError *error) {
        
        
    }];
    
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [textField resignFirstResponder];
    
    return YES;
}
- (IBAction)MakeSureBtn:(UIButton *)sender {
    if (!_OwnCardName.text.length) {
        [SVProgressHUD showErrorWithStatus:@"持卡人姓名不能为空" ];
    }else if(!_BrankNum.text.length){
        [SVProgressHUD showErrorWithStatus:@"卡号不能为空" ];
        
    }else if(!_OwnCardNameProfession.text.length){
        [SVProgressHUD showErrorWithStatus:@"身份证号不能为空" ];
        
    }else if (!_AccountName.text.length){
        [SVProgressHUD showErrorWithStatus:@"开户行不能为空" ];
        
    }else{
         [self requestData];
    }
   
}

- (void)bankCardBackAction{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
